package cn.tedu.oop;

public class TestCat {
    public static void main(String[] args) {
        /*//6.1使用无参构造创建对象
        Cat c1 = new Cat();
        //6.2通过set()给对象的属性赋值
       c1.setName("叮当");
        c1.setAge(300);
        c1.setHost("大雄");
        c1.setKind("机器猫");
        c1.setPrice(10000);
        //6.3通过get()查看对象的属性值
        System.out.println(c1.getName());
        System.out.println(c1.getHost());
        System.out.println(c1.getAge());
        System.out.println(c1.getPrice());
        System.out.println(c1.getKind());

        //7.1使用全参构造创建对象,并同时给对象的所有属性赋值,//传参就相应对象的属性默认给赋值
        Cat c2 = new Cat("罗小黑",7,"变异猫","未知",800);
        //7.2查看对象的赋值是否成功
        System.out.println(c2.getName());
        System.out.println(c2.getHost());
        System.out.println(c2.getAge());
        System.out.println(c2.getPrice());
        System.out.println(c2.getKind());

         //8.1创建小猫类的对象*/
        Cat c3 = new Cat();
        //8.2通过创建好的小猫对象调用小猫类的功能
        /*c3.eat(8);
        c3.sleep("罗小白",9.9);
        c3.jump("花花");*/
        //c3.play("苏大强");//只调用玩的功能,不接收返回值
        /*System.out.println(c3.play("光头强~"));
        String n = c3.play("哈哈哈");//再次调用play(),选择接收返回值
        System.out.println(n);//把接到的玩具"逗猫棒"打印出来
        System.out.println(c3.play("哈哈哈!"));//把接到的玩具"逗猫棒"打印出来*/

        //System.out.println(c3.play("~布索~"));
        String str = c3.play("阿猫");
        System.out.println(str);
    }
}
//1.定义小猫类
class Cat{

    /*public static void main(String[] args) {
        bark();
    }*/


    //2.1提供所有属性并进行封装
    private String name;//名字
    private int age;//年龄
    private String kind;//品种
    private String host;//主人
    private double price;//价格

    //5.创建构造代码块,提取所有构造方法的共性功能//先执行构造代码块,下只执行无参构造
    {
        System.out.println("又有一只可爱的小猫咪粗来啦~");
    }

    //3.提供本类的无参与全参构造
    public Cat() {
        System.out.println("无参构造");
    }

    /*public Cat() {
    }*/

    public Cat(String name, int age, String kind, String host, double price) {
        this.name = name;
        this.age = age;
        this.kind = kind;
        this.host = host;
        this.price = price;
        System.out.println("全参构造");
    }

    //4.提供小猫类的功能
    //4.1睡觉sleep:参数String name,double num,无返回值,打印:小猫name今天一共睡了num个小时
    public void sleep(String name,double num){
        System.out.println("小猫"+name+"今天一共睡了"+num+"个小时");
    }
    //4.2玩play: 参数String host,返回值String"逗猫棒",打印:小猫与主人host玩的很开心
    public String play(String host){
        System.out.println("小猫与主人"+host+"玩的很开心");

        bark();//此处调用被封装的方法 //只调用方法,只打印sout,不打印return
        //System.out.println(bark()); //打印方法:1)可以打印方法里面的sout和return的返回值;2)打印方法可以嵌套
        return "逗猫棒";
    }
    //4.3叫bark:打印:小猫喜欢喵喵叫,此方法要封装,玩的时候才叫,,,,玩的时候才叫,调用私有方法
    private /*static*/ String bark(){
        System.out.println("小猫喜欢喵喵叫");
        return "小皮球";
    }

    //4.4吃eat:参数int n,无返回值,打印:小猫Cat今晚要吃n根肉骨头
    public void eat(int n){
        System.out.println("小猫Cat今晚要吃"+n+"根肉骨头");
        //return;
        //System.out.println();
    }
    //4.5跳jump:参数String name,无返回值,打印:小猫name跳的老高啦~
    public void jump(String name){
        System.out.println("小猫"+name+"跳的老高啦~");
    }

    //2.2给被封装的属性提供get与set方法,,,被封装的属性//传参就给相应对象的属性默认给赋值
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getKind() {
        return kind;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}